﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using EPiServer.Core;

namespace TemplateFoundation.WebControls.Admin
{
    /// <summary>
    /// Used to display a table with all page properties and their values
    /// </summary>
    public class PagePropertyList : WebControlBase
    {
        /// <summary>
        /// Creates a new PagePropertyList control
        /// </summary>
        public PagePropertyList() : base(HtmlTextWriterTag.Table)
        {
            
        }

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            foreach (PropertyData property in CurrentPage.Property)
            {
                if (property.Value==null)
                    continue;

                var row = new HtmlTableRow();

                var name = new HtmlTableCell()
                                   {
                                       InnerText = property.Name
                                   };

                var value = new HtmlTableCell()
                                   {
                                       InnerText = property.Value.ToString()
                                   };

                row.Cells.Add(name);
                row.Cells.Add(value);

                Controls.Add(row);
            }
        }
    }
}
